package com.tianyi.sfzy1.controller;

import com.tianyi.sfzy1.util.AliOSSUtil;
import com.tianyi.sfzy1.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;



@RestController
@RequestMapping("/file")
public class FileController {
    @Autowired
    private AliOSSUtil aliOSSUtil;
    @PostMapping
    public String upload(@RequestParam("file") MultipartFile image) throws IOException {
        //把图片直接上传的阿里云oss服务器中
        String url = aliOSSUtil.uploadFile(image);
        return url;
    }

    @PostMapping("/upload1")
    public R upload1(@RequestParam("file") MultipartFile image) throws IOException {
        //把图片直接上传的阿里云oss服务器中
        String url = aliOSSUtil.uploadFile(image);
        return R.ok(url);
    }
}
